package cn.yunhe.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.yunhe.biz.IRoleBiz;
import cn.yunhe.entity.Role;
@Controller
public class Rolecontorller {
	
	@Autowired
	@Qualifier("roleBiz")
	private IRoleBiz roleBiz;
	public IRoleBiz getRoleBiz() {
		return roleBiz;
	}
	public void setRoleBiz(IRoleBiz roleBiz) {
		this.roleBiz = roleBiz;
	}
	
	@RequestMapping("/Roleindex.do")
	public String Roleindex(String rName,HttpSession session){
		List<Role> list = roleBiz.FindAllRole(rName);
		session.setAttribute("Role", list);
		return "Role/index";
	}
	
	@RequestMapping("/addRole.do")
	public String addRole(){
		return "Role/addRole";
	}
	
	@RequestMapping("/editRole.do")
	public String editRole(Integer rId,HttpSession session){
		Role role = roleBiz.FindRoleById(rId);
		if(role!=null){
			session.setAttribute("role", role);
			return "Role/editRole";
		}else{
			return "redirect:/Roleindex.do";			
		}
	}
	
	@RequestMapping("/delrole.do")
	public String delrole(Integer[] rId){
		Integer i = 0;
		for(Integer j=0;j<rId.length;j++){
			Boolean flag = roleBiz.DelRoleById(rId[j]);
			if(flag){
				i++;
			}
		}
		if(i==rId.length){
			return "redirect:/Roleindex.do";
		}else{
			return "Role/index";	
		}
	}
	
	
}
